package com.thinkcube.edutainment.service.viewitem;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.thinkcube.edutainment.R;
import com.thinkcube.edutainment.domain.data.CourseData;

/**
 * Shanuka @Cyberlmj 3:08:30 PM Email: shanuka.gayashan@cyberlmj.com
 */
@EViewGroup(R.layout.mycourse_item)
public class MyCourseItem extends RelativeLayout {

	@ViewById(R.id.imageView)
	ImageView imageView;

	@ViewById(R.id.textViewTitle)
	TextView textViewTitle;

	@ViewById(R.id.progressBar1)
	ProgressBar progressBar;

	public MyCourseItem(final Context context) {
		super(context);

	}

	private DisplayImageOptions options;
	private ImageLoader imageLoader;

	@AfterViews
	void initAdapter() {
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.icon)
				.showImageForEmptyUri(R.drawable.icon)
				.showImageOnFail(R.drawable.icon).cacheInMemory(true)
				.cacheOnDisc(true).displayer(new SimpleBitmapDisplayer())
				.build();
		imageLoader = ImageLoader.getInstance();
	}

	public MyCourseItem(final Context context, final AttributeSet attrs) {
		super(context, attrs);
	}

	public void bind(final CourseData courseData) {
		textViewTitle.setText(courseData.getCourseTitle());
		imageLoader.displayImage(courseData.getCourseIconLarge(),
				imageView, options);
		
		System.out.println("COURSE iMAGE >>>>"+courseData.getCourseCoverImageSnall());

		if (courseData.getProgress() != null) {
			progressBar.setProgress(Integer.valueOf(courseData.getProgress()));
		}
	}
}
